cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

macro(test_llvm_cmake_variable VARIABLE)
    if(NOT DEFINED ${VARIABLE})
        message(FATAL_ERROR "${VARIABLE} is not defined")
    endif()
    message(STATUS "${VARIABLE}: ${${VARIABLE}}")
endmacro()

set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} test_package.cpp)

if (LLVM_SHARED)
    find_package(LLVM REQUIRED)
    target_link_libraries(${PROJECT_NAME} PRIVATE LLVM)
else()
    find_package(LLVM REQUIRED)
    llvm_map_components_to_libnames(llvm_libs interpreter nativecodegen irreader)
    target_link_libraries(${PROJECT_NAME} PRIVATE ${llvm_libs})
endif()

message(STATUS "Testing LLVM Build Module Variables")
test_llvm_cmake_variable(LLVM_PACKAGE_VERSION)
test_llvm_cmake_variable(LLVM_BUILD_TYPE)
test_llvm_cmake_variable(LLVM_CMAKE_DIR)
test_llvm_cmake_variable(LLVM_TOOLS_BINARY_DIR)
test_llvm_cmake_variable(LLVM_ALL_TARGETS)
test_llvm_cmake_variable(LLVM_TARGETS_TO_BUILD)
test_llvm_cmake_variable(LLVM_TARGETS_WITH_JIT)
test_llvm_cmake_variable(LLVM_NATIVE_ARCH)
